package com.itheima.a03udpdemo;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class ReceiveMessageDemo {
    public static void main(String[] args) throws IOException {
        DatagramSocket ds = new DatagramSocket(10086);

        byte[] bytes = new byte[1024];
        DatagramPacket dp = new DatagramPacket(bytes,bytes.length);

        while (true) {
            ds.receive(dp);
            String hostAddress = dp.getAddress().getHostAddress();
            String hostName = dp.getAddress().getHostName();
            byte[] data = dp.getData();
            System.out.println("ip为"+hostAddress+"主机号为"+hostName+"发送来了数据，"+new String(data));
        }


    }
}
